<?php
use yii\helpers\Url;
use yii\Web\View;
use app\assets\LaunchDetailsAsset;
/* @var $this yii\web\View */
LaunchDetailsAsset::register($this); 
$this->title = $this->context->pageTitle.Yii::$app->params['titleSuffix'];
$this->params['breadcrumbs'] = [
  [
    'label' => \Yii::t('campaign', 'Campaign'),
    'url' => ['launch-list']
  ],
  \Yii::t('campaign', 'New Campaign')
];
$jsMsgs = $this->context->loadJsMsgs([
  'campaignForm',
  'dateRange',
  'launch'
]);
$this->registerJs("VAM.setVar('LANGUAGE_JS', '".$jsMsgs."');", View::POS_HEAD);
?>
<div class="page-header">
  <h1>
    <?=\Yii::t('campaign', 'Campaign')?>
    <small><?=\Yii::t('campaign', 'New Campaign')?></small>
  </h1>
</div>
<div class="panel panel-default">
  <div class="panel-heading">
    <i class="fa fa-plus-circle"></i>
    <?=\Yii::t('campaign', 'New Campaign')?>
    <ul class="list-unstyled pull-right">
      <li>
        <a href="#">
          <i class="fa fa-chevron-up"></i>
        </a>
      </li>
    </ul>
  </div>
	<div class="panel-body">
    <div class="step-container">
      <ul class="step-wrap">
        <li class="step-undone step-done">
          <a href="javascript:void(0);" title="<?=\Yii::t('common', 'Add Label')?>"><i class="fa fa-check"></i></a>
          <p><?=\Yii::t('common', 'Add Label')?></p>
        </li>
        <li class="step-undone step-active">
          <a href="javascript:void(0);" title="<?=\Yii::t('common', 'Add Campaign')?>">
            <i class="fa fa-chevron-right"></i>
          </a>
          <p><?=\Yii::t('common', 'Add Campaign')?></p>
        </li>
         <li class="step-undone">
          <a href="javascript:void(0);" title="<?=\Yii::t('common', 'Add Solution')?>">
            <i class="fa fa-chevron-right"></i>
          </a>
          <p><?=\Yii::t('common', 'Add Solution')?></p>
        </li>
         <li class="step-undone">
          <a href="javascript:void(0);" title="<?=\Yii::t('common', 'Add Creative')?>">
            <i class="fa fa-chevron-right"></i>
          </a>
          <p><?=\Yii::t('common', 'Add Creative')?></p>
        </li>
      </ul>
      <div class="step-progress-bar">
        <div class="step-progress" style="width: 34.7%;"></div>
      </div>
    </div>
		<div class="row">
			<div class="col-sm-8 col-sm-offset-2">
        <form action="<?php echo Url::to(['launch/new-launch-handle']);?>" method="post" class="form-horizontal" id="data-frm">
          <input class="hidden" type="text" name="id" value="">
          <fieldset>
            <legend><?=\Yii::t('campaign', 'Campaign Info')?></legend>
            <div class="form-group">
              <label for="launch_name" class="col-sm-3 control-label">
                <em>*</em>
                <?=\Yii::t('campaign', 'Campaign Name')?>：
              </label>
              <div class="col-sm-9">
                <input type="text" class="form-control" id="launch_name" name="name" value="" placeholder="<?=\Yii::t('campaign', 'Campaign Name')?>">
                <div class="help-block text-error" id="launch_name_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label for="belong_campaign" class="col-sm-3 control-label">
                <em>*</em>
                <?=\Yii::t('campaign', 'Label')?>：
              </label>
              <div class="col-sm-9">
                <select class="form-control" id="belong_campaign" name="label_id" placeholder="<?=\Yii::t('campaign', 'Label')?>">
      					<?php 
      						foreach($labels as $label) {
      							$id = $label['id'];
      							$name = $label['name'];
      							$isSelected = '';
      							if ($bindLabelId == $id) $isSelected="selected";
      							echo "<option value='$id' $isSelected>$name</option>";
      						}
      					?>
                </select>
                <div class="help-block text-error" id="belong_campaign_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label for="total_budget" class="col-sm-3 control-label">
                <em>*</em>
                <?=\Yii::t('campaign', 'Total Budget')?>：
              </label>
              <div class="col-sm-9">
                <input type="text" min="0" class="form-control" id="total_budget" name="total_budget" value="" placeholder="<?=\Yii::t('campaign', 'Total Budget')?>">
                <div class="help-block"><?=\Yii::t('campaign', 'Total budget not below')?>：<span class="min-total-budget"><?=$totalBudget?></span>￥</div>
                <div class="help-block text-error" id="total_budget_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label for="start_date" class="col-sm-3 control-label">
                <em>*</em>
                <?=\Yii::t('common', 'Date Range')?>：
              </label>
              <div class="col-sm-9">
                <div class="input-group">
                  <span class="input-group-btn">
                    <button class="btn btn-default" id="range-date-btn" type="button" title="<?=\Yii::t('common', 'Select Date Range')?>"><i class="fa fa-calendar"></i></button>
                  </span>
                  <input type="text" class="form-control" id="range-date" name="range_date" value="" placeholder="<?=\Yii::t('common', 'Select Date Range')?>，<?=\Yii::t('common', 'format YYYY-MM-DD - YYYY-MM-DD')?>" readonly>
                </div>
                <div class="help-block text-error" id="range_date_err"></div>
              </div>
            </div>
          </fieldset>
          <fieldset class='vam-hidden'>
            <div class="form-group">
              <label for="start_date" class="col-sm-3 control-label">
                <?=\Yii::t('campaign', 'Solution Type')?>：
              </label>
              <div class="col-sm-9">
                <?php
                $pc = \Yii::t('campaign', 'PC Solution');
                $pcStrategy = <<<FINE
                <label class="radio-inline">
                  <input type="radio" class="strategy_type" name="strategy_type" value="pc"> $pc
                </label>
FINE;
                if (in_array(1, $_SESSION['traffic_slot']) || in_array(2, $_SESSION['traffic_slot'])) echo $pcStrategy;
                ?>
                <?php
                $mobile = \Yii::t('campaign', 'Mobile Solution');
                $check = 'checked';
                if(!(in_array(1, $_SESSION['traffic_slot']) || in_array(2, $_SESSION['traffic_slot']))
                   && (in_array(3, $_SESSION['traffic_slot']) || in_array(4, $_SESSION['traffic_slot']))) {
                  $check = 'checked';
                }
                $mobileStrategy = <<<FINE
                <label class="radio-inline">
                  <input type="radio" class="strategy_type" name="strategy_type" value="mobile" $check> $mobile
                </label>
FINE;
                if (in_array(3, $_SESSION['traffic_slot']) || in_array(4, $_SESSION['traffic_slot'])) echo $mobileStrategy;
                ?>
                <div class="help-block"><?=\Yii::t('campaign', 'Solution type on next step')?></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label">
                <?=\Yii::t('campaign', 'Union Frequency Control')?>：
              </label>
              <div class="col-sm-9">
                <div class="form-group">
                  <label class="radio-inline col-sm-3">
                    <input type="radio" class="frequency-control-type" name="frequency_control" value="1"><?=\Yii::t('campaign', 'Yes')?>
                  </label>
                  <label class="radio-inline col-sm-3">
                    <input type="radio" class="frequency-control-type" name="frequency_control" value="0" checked><?=\Yii::t('campaign', 'No')?>
                  </label> 
                </div>
                <div class="form-group" id="union_frequency_ctrl">
                  <div class="form-group">
                    <label class="control-label col-sm-2 plr0">
                      <?=\Yii::t('campaign', 'Frequency Ctrl Range')?>：
                    </label>
                    <div class="col-sm-9">
                      <div class="col-sm-7 pl0">
                        <select name="frequency_control_type" class="form-control">
                            <option value="2"><?=\Yii::t('campaign', 'Launch Rang')?></option>
                            <option value="5"><?=\Yii::t('campaign', 'Every weekly')?></option>
                            <option value="4"><?=\Yii::t('campaign', 'Every day')?></option>
                            <option value="3"><?=\Yii::t('campaign', 'Every hour')?></option>
                        </select>
                      </div>
                    </div>
                  </div>
                  <div class="form-group">
                    <label class="control-label col-sm-2 plr0">
                      <?=\Yii::t('campaign', 'Upper Limit')?>：
                    </label>
                    <div class="col-sm-9">
                      <div class="col-sm-7 pl0">
                        <input type="text" id="frequency_upper_limit" name='frequency_upper_limit' class="form-control" value="">
                        <div class="help-block text-error"></div>
                      </div>
                    </div>
                  </div>

                  <div class="form-group">
                    <label class="control-label col-sm-2 plr0">
                      <?=\Yii::t('campaign', 'Lower Limit')?>：
                    </label>
                    <div class="col-sm-9">
                      <div class="col-sm-7 pl0">
                        <input type="text" id="frequency_lower_limit" name='frequency_lower_limit' class="form-control" value="">
                        <div class="help-block text-error"></div>
                      </div>
                    </div>
                  </div>

                  <div class="form-group">
                    <label class="control-label col-sm-2 plr0">
                      <?=\Yii::t('campaign', 'Lower Limit Open Date')?>：
                    </label>
                    <div class="col-sm-9">
                      <div class="col-sm-7 pl0">
                        <div class="input-group">
                          <span class="input-group-btn">
                            <button class="btn btn-default" id="frequency-range-date-btn" type="button" title="<?=\Yii::t('common', 'Select Date Range')?>"><i class="fa fa-calendar"></i></button>
                          </span>
                          <input type="text" class="form-control" id="frequency-open-date" name="frequency_lower_start" value="" placeholder="<?=\Yii::t('common', 'Select Date')?>，<?=\Yii::t('common', 'format YYYY-MM-DD')?>" readonly>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </fieldset>
          <fieldset>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10 col-xs-11">
                <div class="btn-form-group pull-right">
                  <input class="operate-type" type="hidden" name="operate_type" value="save">
                  <button type="submit" class="btn btn-primary save-btn" data-operate="save" data-loading-text="<i class='fa fa-spinner fa-spin'></i> <?=\Yii::t('common', 'Saving')?>..."><?=\Yii::t('common', 'Save')?></button>
                  <button type="submit" class="btn btn-success save-next-btn" data-operate="save-next" data-loading-text="<i class='fa fa-spinner fa-spin'></i> <?=\Yii::t('common', 'Saving')?>...">
                    <?=\Yii::t('campaign', 'Save and Create Solution')?>
                    <i class="fa fa-caret-right"></i>
                  </button>
                  <a href="<?php echo Url::to(['launch/launch-list']); ?>" class="btn btn-default"><?=\Yii::t('common', 'Back')?></a>
                </div>
              </div>
            </div>
          </fieldset>
        </form>
      </div>
		</div>
	</div>
</div>
<?php
  $nextMobleUrl = Url::to(['solution/new-solution-basic']);
  $nextPcUrl = Url::to(['solution/new-solution-basic']);
  $this->registerJs("VAM.setVar('NEXT_MOBILE_URL','$nextMobleUrl');",View::POS_HEAD);
  $this->registerJs("VAM.setVar('NEXT_PC_URL','$nextPcUrl');",View::POS_HEAD);
?>
<script type="text/javascript" >
  requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/site.js"], function(common) {
    requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/launch/newLaunch.js"]);
  });
</script>
